package com.hg.library.graph;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.Transformation;

/**
 * Created by ASUS-PC on 2016/4/15.
 */
public class FilpAnimation extends Animation{

    private float mCenterX = 0;
    private float mCenterY = 0;
    private boolean order;

    private float angle = 30;
    private Camera camera = new Camera();

    public FilpAnimation(float mCenterX, float mCenterY, float angle) {
        this(mCenterX,mCenterY,angle,false);
    }

    public FilpAnimation(float mCenterX, float mCenterY, float angle,boolean order) {
        this.mCenterX = mCenterX;
        this.mCenterY = mCenterY;
        this.angle = angle;
        this.order = order;
    }

    @Override
    public boolean getTransformation(long currentTime, Transformation outTransformation, float scale) {
        return super.getTransformation(currentTime, outTransformation, scale);
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        Matrix matrix = t.getMatrix();
        if (order)
            interpolatedTime = 1 - interpolatedTime;
        camera.save();
        camera.rotateY(angle * interpolatedTime);
        camera.getMatrix(matrix);
        camera.restore();
        matrix.preTranslate(-mCenterX, -mCenterY);
        matrix.postTranslate(mCenterX, mCenterY);
    }
}
